$("<link>").attr({ 
	rel: "stylesheet",
    type: "text/css",
    href: "/Public/Home/js/msgbox/style.css?" + Math.random()
}).appendTo("head");


function loading(){
	$(".mb-msgbox").remove();
	removeLoading();
	$("body").append("<div class='loading-box' id='loading'><div class='loading'></div></div>");
	var left = ($(document).outerWidth()-$('#loading').outerWidth())/2;
	var top = ($(window).outerHeight()-$('#loading').outerHeight())/2;
	$("#loading").css({left:left+'px'});
	$("#loading").css({top:top+'px'});
}

function removeLoading(){
	$("#loading").remove();
}

function _confirm (msg,url, opt_type, cont_id, btn_ok_name) {
	var opt_type = opt_type ? opt_type : '';
	var cont_id  = cont_id ? cont_id : '';
	var msg      = msg ? msg : '您确定要进行此操作吗？';
	var btn_ok_name = btn_ok_name ? btn_ok_name : '确认';
	html = '<div style="width:300px;" class="ajax_confirm">';
	html += '<div>' + msg + '</div>';
	html += '<div style="text-align:center;margin-top:8px">';
	html += '<span class="btn-confirm">' + btn_ok_name + '</span>';
	html += '<span class="btn btn-cancel" onclick="$.winRemove()">取消</span>';
	html += '</div></div>';
	$.win_info('',html,'提示信息');
	$('.ajax_confirm .btn-confirm').click(function () {
		switch(opt_type){
			case 'delete':
				loading('正在删除中，请稍候...');
				$.ajax({
					type: "get",
					url: url,
					success : function(data){
						removeLoading();
						if(data.status==200){
							msgbox(data.info);
							$(cont_id).fadeOut('slow', function () {
								$(cont_id).remove();
							});
						}else{
							msgbox(data.info,'error');
						}
						$.winRemove();
					},
					error :function (data) {
						removeLoading();
						msgbox('请求失败，请稍候再试！','error');
					}
				});
				break;
			default:
				jumpurl(url);
		}
		return false;
	});
	return false;
}

/**
 * JS消息盒子
 * @param msg 信息
 * @param type 类型，有warn、success、error默认为success
 * @param redirect 重定向地址
 * @param timeout 缓冲时间，默认3秒
 * @return
 */
var msg_handle;
function msgbox(msg,type,redirect,timeout){
	var type = type ? type : 'success';
	var msg  = msg ? msg : '请求数据有误！';
	$(".mb-msgbox").remove();
	var left = ($(document).width()-240)/2;
	$("body").append("<div class='mb-msgbox'>"+msg+"</div>");
	var left = ($(document).outerWidth()-$('.mb-msgbox').outerWidth())/2;
	var top = ($(window).outerHeight()-$('.mb-msgbox').outerHeight())/2;
	$(".mb-msgbox").css({left:left+'px'});
	// $(".mb-msgbox").css({top:top+'px'});
	
	clearTimeout(msg_handle);
	timeout = timeout > 0 ? timeout : 3;
	msg_handle = setTimeout(function(){
		$(".mb-msgbox").remove();
		clearTimeout(msg_handle);
		if(redirect) document.location.href = redirect;
	},timeout*1000);
}
